/**
 * 初始化爬虫管理详情对话框
 */
var CrawlerMgrAddDlg = {
    data: {
        source: "",
        logoUrl: "",
        sourceUrl: "",
        status: ""
    }
};

/**
 * 关闭此对话框
 */
CrawlerMgrAddDlg.close = function () {
    parent.layer.close(window.parent.CrawlerMgr.layerIndex);
};

/**
 * 验证表单
 */
CrawlerMgrAddDlg.validateForm = function () {

    var data = CrawlerMgrAddDlg.data;

    if (!data.source) {
        return "来源不能为空";
    }
    if (!data.status) {
        return "状态不能为空";
    }
    if (!data.sourceUrl) {
        return "网站地址不能为空";
    }
    return true;
};

/**
 * 提交添加任务
 */
CrawlerMgrAddDlg.addSubmit = function() {
    var ajax = new $ax(Feng.ctxPath + "/crawlerMgr/add", function(data){
        parent.Feng.success("添加成功!");
        window.parent.CrawlerMgr.table.refresh();
        CrawlerMgrAddDlg.close();
    },function(data){
        parent.Feng.error("添加失败!" + data.responseJSON.message + "!");
    });
    ajax.set(this.data);
    ajax.start();
}

$(function() {
    CrawlerMgrAddDlg.app = new Vue({
        el: '#crawlerMgrForm',
        data: CrawlerMgrAddDlg.data,
        methods: {
            submitForm: function (e) {
                e.preventDefault();
            },
            ensure: function () {
                var result = CrawlerMgrAddDlg.validateForm();
                if (result === true) {
                    CrawlerMgrAddDlg.addSubmit();
                } else {
                    Feng.alert(result);
                }
            },
            close: function () {
                CrawlerMgrAddDlg.close();
            }
        }
    })
});
